package com.jflm.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jflm.service.IIpService;
import com.jflm.service.IPropertyService;
import com.jflm.util.IPUtil;

/**
 * ******************  类说明  *********************
 * class       :  IpServiceImpl
 * @author     :  hejinyun@umfintech.com
 * @version    :  1.0  
 * description :  ip服务层接口实现
 * @see        :                        
 * ***********************************************
 */
@Service("ipService")
public class IpServiceImpl implements IIpService {
	
	@Autowired
	private IPropertyService propertyService;
	
	public String ipSuffix() {

		// 获取网卡名称
		String networkCard = propertyService.getStrValue("network.card", "eth0");
		String ip = IPUtil.getHostAddress(networkCard);
		if (StringUtils.isBlank(ip)){
			ip = propertyService.getStrValue("network.ip", ".01");
		}
		String ipSuffix = ip.substring(ip.lastIndexOf(".") + 1);
		
		return String.format("%03d", Integer.valueOf(ipSuffix));
	}

}
